<template>
  <a-modal
    :title="title"
    :visible="visible"
    :width="1000"
    :confirm-loading="loading"
    @ok="handleOk"
    @cancel="$emit('cancel')"
  >
    <template slot="footer">
      <a-button
        key="back"
        @click="$emit('cancel')"
      >
        取消
      </a-button>
      <a-button
        key="other"
        type="primary"
        :loading="loading"
        @click="handleOk('SUBMITTED')"
      >
        提交
      </a-button>
    </template>
    <a-spin :spinning="loading">
      <a-form-model
        ref="form"
        :model="queryParam"
        :label-col="labelCol"
        :wrapper-col="wrapperCol"
        :rules="rules"
      >
        <a-form-model-item
          label="销项说明"
          prop="comment"
        >
          <BaseTextarea v-model.trim="queryParam.comment" />
        </a-form-model-item>
        <a-form-model-item label="销项证明附件上传">
          <!--                    <l-table v-if="visible" @fileArrysData="fileArrysData" :businessCode="businessCode"></l-table>-->
          <b-upload
            upload-type="single"
            :file-list.sync="queryParam.fileInfoList"
            :business-code="businessCode"
          />
        </a-form-model-item>
      </a-form-model>
    </a-spin>
  </a-modal>
</template>

<script>
import { packageConfirm } from '@/utils/baseAction.js'
export default {
  name:'a'+Date.now(),
  props: {
        visible: {
            type: Boolean,
            default: () => false
        },
        loading: {
            type: Boolean,
            default: () => false
        },
        title: {
            type: String,
            default: () => ''
        },
        model: {
            type: Object,
            default: () => null
        },
        form: {
            type: Object,
            default: () => {
            }
        }
    },
    data() {
        return {
            queryParam: {
                fileInfoList: []
            },
            labelCol: { span: 3 },
            wrapperCol: { span: 21 },
            businessCode: 'LCM01',
            rules: {
                comment: [{ required: true, message: '请输入销项说明', trigger: 'blur' }]
            }
        }
    },
    watch: {
        visible(e) {
            if (!e) {
                this.queryParam = {}
                this.$refs.form.clearValidate()
            } else {
                this.queryParam = this.$clone(this.form.destroyedBusDTO)
                if (this.queryParam.comment) this.queryParam.comment = this.queryParam.comment
                if (this.queryParam.fileInfoVos) this.queryParam.fileInfoList = this.queryParam.fileInfoVos
                console.log(this.queryParam)
            }
        }
    },
    methods: {
        handleOk(status) {
            this.$refs.form.validate((valid) => {
              if(!valid) {
                  this.$message.warning("请填写完所有必填项信息")
                return}
              packageConfirm({
                content: '请确认是否要提交，提交后不可修改',
                okText: '提交',
                cancelText: '关闭'
              }).then(flag => {
                if(flag === 'cancel') return
                this.queryParam.legalAuditStatusEnum = status
                this.$emit('ok', this.queryParam)
              })
            })
        },
        fileArrysData(val) {
            this.queryParam.fileInfoList = val
        },
        handleChange(info) {
            if (info.file.status !== 'uploading') {
                this.queryParam.annex = info.fileList
            }
            if (info.file.status === 'done') {
                this.$message.success(`${info.file.name} file uploaded successfully`)
            } else if (info.file.status === 'error') {
                this.$message.error(`${info.file.name} file upload failed.`)
            }
        }
    }
}
</script>

<style scoped>
</style>
